# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
from airtest.core.android.android import Android
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest
        
class Club_ShareClub(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))

        clubName = "AT_"
        if "clubName" in args:
            clubName = args["clubName"]

        clubHomePageLayer = poco("ClubHomePageLayer")

        if not clubHomePageLayer.exists():
            return False

        myCreateList = clubHomePageLayer.offspring("my_create_list")
        clubItems = myCreateList.offspring("my_create_item")
        for i in range(0, len(clubItems)):
            txtName = clubItems[i].offspring("club_name").get_text()
            if txtName.startswith(clubName):
                self.clickButton(clubItems[i])
                break

        clubPageLayer = poco("ClubPageLayer")
        btnInfoNormal = clubPageLayer.offspring("info_normal")
        btnInfoSelect = clubPageLayer.offspring("info_select")

        # 切换到俱乐部管理面板
        if not btnInfoSelect.exists():
            self.clickButton(btnInfoNormal)

        btnShare = clubPageLayer.offspring("green_btn")
        self.clickButton(btnShare)

        clubShareLayer = clubPageLayer.offspring("ClubShareLayer")
        if not clubShareLayer.exists():
            return False
        
        btnWechat = clubShareLayer.offspring("btn_share_wx")
        if btnWechat.exists():
            self.clickButton(btnWechat)

        try:
            pos = assert_exists(Template(r"tpl1534498156734.png", record_pos=(-0.397, -0.34), resolution=(1080, 1920)), "请填写测试点")
            
            android = Android()
            displayInfo = android.display_info
            
            poco.click([0.5, (pos[1] + 50) / displayInfo["height"]])
            
            text("自动化测试分享", False)
            
            assert_exists(Template(r"tpl1534501448515.png", record_pos=(0.255, 0.353), resolution=(1080, 1920)), "点击分享")

            touch(Template(r"tpl1534501448515.png", record_pos=(0.255, 0.353), resolution=(1080, 1920)))
            
            assert_exists(Template(r"tpl1534501706881.png", record_pos=(-0.162, 0.203), resolution=(1080, 1920)), "请填写测试点")
            
            touch(Template(r"tpl1534501706881.png", record_pos=(-0.162, 0.203), resolution=(1080, 1920)))
        except:
            print("")

        btnCloseShare = clubShareLayer.offspring("btn_share_close")
        self.clickButton(btnCloseShare)

        btnBack = clubPageLayer.offspring("back_btn")
        self.clickButton(btnBack)

        return True
        
_instance = Club_ShareClub()
runTest = _instance.runTest
